// pages/biz/broker/broker.js
import Serv from './brokerServ';
var regeneratorRuntime = require("../../../lib/js/runtime-module.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userAgent: [],
    brokerTotal: 0,
    bgNum: '',
  },
  //获取经济人列表
  userAgent: async function (params, isPush) {
    let {
      rows,
      success,
      msg,
      pageNo,
      total
    } = await Serv.userAgent(params)
    if (success) {
      if (rows[0]&&rows[0].brokers.length!=0){
        rows[0].brokers.map(item =>{
          item.createTime = item.createTime.substr(0, item.createTime.length - 9)
          item.createTime = item.createTime.replace(/-/g, '.')
        })
        if (isPush==0){
          this.setData({
            userAgent: rows[0].brokers,
            brokerTotal: total,
            pageNo
          })
        }else{
          let {userAgent} = this.data
          userAgent.push(...rows[0].brokers)
          this.setData({
            userAgent,
            brokerTotal: total,
            pageNo
          })
        }
      }
    } else {
      console.log(msg)
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.userAgent({},2)
  },
  //专属海报
  sharePoster() {
    // debugger
    // let bgNum = parseInt(3 * Math.random());
    let bgNum =0;
    wx.navigateTo({
      url: `/subPackages/pages/housePoster/housePoster?pageName=index&num=${bgNum}`
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let total = this.data.brokerTotal // 总条数
    let { userAgent } = this.data;
    console.log(total);
    let totalPage = 1 // 总页数
    if (total % 10 === 0) {
      totalPage = total / 10
    } else {
      totalPage = total / 10 + 1
    }
    let pageNo = this.data.pageNo // 当前页数
    // debugger
    if (userAgent.length < total) { // 如果当前条数小于总条数
      let params = {
        pageNo: pageNo + 1,
        pageSize: 10
      }
      this.setData({
        pageNo: pageNo + 1
      })
      pageNo += 1;
      this.userAgent(params,1)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})